// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uoc.tfc.service;

import java.util.Collection;

import edu.uoc.tfc.dbmodel.Client;
import edu.uoc.tfc.dto.ClientVO;
import edu.uoc.tfc.dto.ResultatCercaClientVO;


/**
 * @see edu.uoc.tfc.service.ClientService
 */
public class ClientServiceImpl
    extends edu.uoc.tfc.service.ClientServiceBase
{

    /**
     * @see edu.uoc.tfc.service.ClientService#cercaClients(edu.uoc.tfc.dto.CriteriaClientVO)
     */
    protected  edu.uoc.tfc.dto.ResultatCercaClientVO handleCercaClients(edu.uoc.tfc.dto.CriteriaClientVO criteriaClient)
        throws java.lang.Exception
    {
		@SuppressWarnings("unchecked")
        Collection<ClientVO> clients =
        		getClientDao().findClientsByCriteria(
        				getClientDao().TRANSFORM_CLIENTVO, criteriaClient);
		
		
		ResultatCercaClientVO resultat = new ResultatCercaClientVO();
		
		resultat.setElements(clients);
		resultat.setTotalRecords(clients.size());		
		return resultat;       	
    }

    /**
     * @see edu.uoc.tfc.service.ClientService#getClient(java.lang.String)
     */
    protected  edu.uoc.tfc.dto.ClientVO handleGetClient(java.lang.String clientId)
        throws java.lang.Exception
    {
    	return (ClientVO) this.getClientDao().
    			load(this.getClientDao().TRANSFORM_CLIENTVO, Long.valueOf(clientId));
        
    }

    /**
     * @see edu.uoc.tfc.service.ClientService#altaClient(edu.uoc.tfc.dto.ClientVO)
     */
    protected  void handleAltaClient(edu.uoc.tfc.dto.ClientVO client)
        throws java.lang.Exception
    {
    	getClientDao().create(Client.Factory.newInstance(
    			client.getDni(),
    			client.getNom(),
    			client.getPrimerCognom(),
    			client.getSegonCognom(),
    			client.getTelefon(),
    			client.getMail(),
    			client.getDataNaixement(),
    			true,
    			null));
    }

    /**
     * @see edu.uoc.tfc.service.ClientService#modificaClient(edu.uoc.tfc.dto.ClientVO)
     */
    protected  void handleModificaClient(edu.uoc.tfc.dto.ClientVO client)
        throws java.lang.Exception
    {
    	client.setActiu(client.getActiu()==null?false:true);
    	getClientDao().update(
    			getClientDao().clientVOToEntity(client));
    }

}